<template>
    <div style="height: 100%; width: 100%; position: relative">
        <div class="pagetop" ref="buttondiv">
            <table style="width: 100%; font-size: 12px" class="table1style" border="0">
                <tr>
                    <td colspan="4">
                        <el-checkbox true-label="1" false-label="0" v-model="chkPatInfo" @change="patinfochange">更新病人信息</el-checkbox>
                        <el-checkbox true-label="1" false-label="0" v-model="chkItemInfo">更新项目信息</el-checkbox>
                        <el-checkbox true-label="1" false-label="0" v-model="chkDelItem" @change="delitemchange" v-if="showchkDelItem == '1'">允许删除项目</el-checkbox>
                        <el-checkbox true-label="1" false-label="0" v-model="chkMixInfo"  >更新混样信息 </el-checkbox>
                    </td>
                </tr>
                <tr>
                    <td style="width: 75px; font-size: 16px; font-weight: bold">条形码：</td>
                    <td align="left">
                        <el-input v-model="txtbarcode" placeholder="请扫描条码" style="width: 700px" id="barcodediv" ref="refbarcode" @keyup.enter.native="scanbarcode(txtbarcode)" @focus="BarCodeSelect" size="medium"></el-input>
                    </td>
                    <td :width="buttonwidth"></td>
                    <td align="right" style="vertical-align: bottom">
                        <el-button @click="btnClear" icon="el-icon-close">清除</el-button>
                    </td>
                </tr>
            </table>
        </div>
        <div class="pagecenter">
            <rm-layout-right splitcolor="white" movingcolor="#0000ff" :splitwidth="5" :fixsize="500">
                <template v-slot:fix>
                    <div style="height: 100%">
                        <rm-layout-top splitcolor="white" :splitwidth="5" :fixsize="230" @click.native="rightclick">
                            <template v-slot:fix>
                                <div style="height: 100%; border: 1px solid #ccc" :key="tablekey">
                                    <vxe-table :data.sync="detail" :loading="right_loading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="right_Table" resizable show-overflow size="mini" stripe>
                                        <vxe-table-column field="seq" title="序号" width="50" header-align="center" align="center"></vxe-table-column>
                                        <vxe-table-column field="req_itemname" title="申请项目名称 " width="166" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="item_price" title="实际价格 " width="88" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="qty" title="数量 " width="57" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="amount" title="金额 " width="57" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="req_itemcode" title="申请项目代码 " width="119" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="his_itemcode" title="HIS原始项目代码 " width="131" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="his_recordid" title="HIS中对应记录号 " width="129" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="combitemna" title="所属组合项目简称 " width="127" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="base_price" title="理论/区域价格 " width="104" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="stat_flag" title="统计标志 " width="79" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="other_flag" title="其它标志 " width="79" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="status" title="状态 " width="58" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="lab_add" title="实验室添加标志 " width="113" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="add_dt" title="添加时间 " width="92" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                                        <vxe-table-column field="add_user" title="添加用户 " width="97" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="req_groupid" title="分单类别ID " width="97" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="charge_flag" title="计价标志 " width="82" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="his_refcol1" title="HIS表相关字段1 " width="137" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="his_refcol2" title="HIS表相关字段2 " width="137" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="his_refcol3" title="HIS表相关字段3 " width="137" header-align="center"></vxe-table-column>
                                        <vxe-table-column field="reportid" title="报告ID " width="80" header-align="center"></vxe-table-column>
                                    </vxe-table>
                                </div>
                            </template>
                            <div style="height: 100%; width: 100%" :key="tablekey">
                                <vxe-table :data.sync="reqLogData" height="auto" highlight-current-row :loading="loading" highlight-hover-row highlight-hover-column resizable show-header-overflow="tooltip" border fit show-overflow="tooltip" header-align="center" size="mini" stripe ref="xTable1" :sort-config="{ trigger: 'cell' }">
                                    <vxe-table-column :field="items.field" :key="items.field" :title="items.title" :width="items.width" sortable v-for="items in reqlogColumn" :formatter="formatfun">
                                        <template v-if="items.field == 'computer_name'" v-slot="{ row }">
                                            <span style="color:blue;">{{row.computer_name}}</span>
                                            <i class="el-icon-refresh" @click="repalceComputerName(row)"></i>
                                        </template>
                                    </vxe-table-column>
                                </vxe-table>
                            </div>
                        </rm-layout-top>
                    </div>
                </template>
                <div style="height: 100%; width: 100%">
                    <vxe-table :data.sync="master" :loading="loading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" @current-change="currentChangeEvent" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="left_Table" resizable show-overflow size="mini" stripe>
                        <!-- <vxe-table-column type="selection" width="50"></vxe-table-column> -->
                        <vxe-table-column field="req_groupna" title="分单类别 " width="110" header-align="center">
                            <template v-slot="{ row }">
                                <div v-bind:style="{ background: $pub.ColorChange(row.tubecolor), color: $pub.colorConvert(row.tubecolor) }" style="height: 20px; width: 120px">{{ row.req_groupna }}</div>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column field="specimen_name" title="标本类型 " width="110" header-align="center"></vxe-table-column>
                        <vxe-table-column field="req_deptname" title="申请科室 " width="104" header-align="center"></vxe-table-column>
                        <vxe-table-column field="req_wardname" title="所属病区 " width="105" header-align="center"></vxe-table-column>
                        <vxe-table-column field="req_bedno" title="床号 " width="74" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_name" title="姓名 " width="84" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_sexname" title="性别 " width="58" header-align="center"></vxe-table-column>
                        <vxe-table-column field="req_statname" title="申请状态 " width="122" header-align="center"></vxe-table-column>
                        <vxe-table-column field="barcode" title="条码号 " width="157" header-align="center"></vxe-table-column>
                        <vxe-table-column field="emer_flag" title="加急 " width="60" header-align="center"></vxe-table-column>
                        <vxe-table-column field="sample_items" title="申请项目(简称，部分) " width="203" header-align="center"></vxe-table-column>
                        <vxe-table-column field="reject_reason" title="踢回原因 " width="205" header-align="center"></vxe-table-column>
                        <vxe-table-column field="base_amount" title="应收金额 " width="105" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_no" title="病历号 " width="105" header-align="center"></vxe-table-column>
                        <vxe-table-column field="req_docname" title="申请医生 " width="115" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_typename" title="病人来源 " width="107" header-align="center"></vxe-table-column>
                        <vxe-table-column field="create_dt" title="创建时间 " width="130" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="create_username" title="创建人 " width="104" header-align="center"></vxe-table-column>
                        <vxe-table-column field="reject_username" title="踢回人 " width="110" header-align="center"></vxe-table-column>
                        <vxe-table-column field="reject_dt" title="踢回时间 " width="128" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="print_dt" title="打印/执行时间 " width="126" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']"></vxe-table-column>
                        <vxe-table-column field="print_username" title="打印/执行人 " width="101" header-align="center"></vxe-table-column>
                        <vxe-table-column field="print_count" title="打印次数 " width="108" header-align="center"></vxe-table-column>
                        <vxe-table-column field="sampled_dt" title="采样时间 " width="121" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="sampled_username" title="采样人 " width="93" header-align="center"></vxe-table-column>
                        <vxe-table-column field="req_dt" title="申请日期 " width="125" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="pat_diag" title="临床诊断 " width="133" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_agestr" title="年龄 " width="68" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_id" title="病人ID号 " width="107" header-align="center"></vxe-table-column>
                        <vxe-table-column field="inp_date" title="入院日期 " width="123" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="send_dt" title="送出时间 " width="126" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="send_username" title="送出人" width="93" header-align="center"></vxe-table-column>
                        <vxe-table-column field="recieve_dt" title="接收时间 " width="126" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="recieve_username" title="接收人 " width="153" header-align="center"></vxe-table-column>
                        <vxe-table-column field="charge_dt" title="计价时间 " width="125" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="charge_username" title="计价人 " width="104" header-align="center"></vxe-table-column>
                        <vxe-table-column field="amount" title="实收总金额 " width="120" header-align="center"></vxe-table-column>
                        <vxe-table-column field="charge_flag" title="计价标志 " width="73" header-align="center"></vxe-table-column>
                        <vxe-table-column field="test_dt" title="上机时间 " width="129" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="test_username" title="上机人 " width="106" header-align="center"></vxe-table-column>
                        <vxe-table-column field="report_dt" title="报告时间 " width="134" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="report_username" title="检验医生姓名 " width="102" header-align="center"></vxe-table-column>
                        <vxe-table-column field="rechk_username" title="核对医生姓名 " width="95" header-align="center"></vxe-table-column>
                        <vxe-table-column field="alter_flag" title="报警 " width="82" header-align="center"></vxe-table-column>
                        <vxe-table-column field="saleman" title="销售员 " width="93" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_cardno" title="就诊卡号 " width="129" header-align="center"></vxe-table-column>
                        <vxe-table-column field="req_comm" title="医生备注 " width="197" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_birth" title="生日 " width="129" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="pat_ageyear" title="年龄岁数 " width="100" header-align="center"></vxe-table-column>
                        <vxe-table-column field="inp_id" title="住院标识/就诊号" width="116" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_diag_icd" title="诊断的ICD10编码 " width="161" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_address" title="地址" width="195" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_nation" title="国家/民族" width="84" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_idcardno" title="身份证号护照号" width="192" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_phone" title="联系电话" width="174" header-align="center"></vxe-table-column>
                        <vxe-table-column field="charge_typename" title="收费类型" width="102" header-align="center"></vxe-table-column>
                        <vxe-table-column field="perform_deptname" title="执行科室" width="103" header-align="center"></vxe-table-column>
                        <vxe-table-column field="original_reqno" title="原始单号" width="150" header-align="center"></vxe-table-column>
                        <vxe-table-column field="secrecy" title="加密" width="97" header-align="center"></vxe-table-column>
                        <vxe-table-column field="other_stat" title="其他状态 " width="96" header-align="center"></vxe-table-column>
                        <vxe-table-column field="cancel_dt" title="作废时间 " width="125" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="cancel_username" title="作废人 " width="105" header-align="center"></vxe-table-column>
                        <vxe-table-column field="reject_count" title="踢回次数 " width="100" header-align="center"></vxe-table-column>
                        <vxe-table-column field="specimen_code" title="标本类型代码 " width="104" header-align="center"></vxe-table-column>
                        <vxe-table-column field="sample_detail" title="标本备注说明 " width="131" header-align="center"></vxe-table-column>
                        <vxe-table-column field="req_reason" title="送检目的 " width="137" header-align="center"></vxe-table-column>
                        <vxe-table-column field="Master_Barcode" title="主申请单ID" width="100" header-align="center"></vxe-table-column>
                        <vxe-table-column field="multi_seq" title="子申请单序号" width="100" header-align="center"></vxe-table-column>
                        <vxe-table-column field="req_groupid" title="分单类别ID" width="100" header-align="center"></vxe-table-column>
                        <vxe-table-column field="report_id" title="报告单ID" width="91" header-align="center"></vxe-table-column>
                        <vxe-table-column field="report_user" title="检验医生" width="101" header-align="center"></vxe-table-column>
                        <vxe-table-column field="rechk_user" title="核对医生" width="110" header-align="center"></vxe-table-column>
                        <vxe-table-column field="recieve1_dt" title="工作组接收时间 " width="129" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                        <vxe-table-column field="recieve1_username" title="工作组接收人" width="129" header-align="center"></vxe-table-column>
                        <vxe-table-column field="inlib_status" title="入库状态 " width="112" header-align="center"></vxe-table-column>
                        <vxe-table-column field="library_id" title="所在库位ID " width="112" header-align="center"></vxe-table-column>
                        <vxe-table-column field="reqtype" title="申请业务类别 " width="118" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_height" title="身高 " width="95" header-align="center"></vxe-table-column>
                        <vxe-table-column field="weight" title="体重 " width="91" header-align="center"></vxe-table-column>
                        <vxe-table-column field="abo_bldtype" title="ABO血型 " width="100" header-align="center"></vxe-table-column>
                        <vxe-table-column field="rh_bldtype" title="RH血型 " width="94" header-align="center"></vxe-table-column>
                        <vxe-table-column field="tubecolor" title="试管颜色 " width="95" header-align="center"></vxe-table-column>
                        <vxe-table-column field="send_user1" title="运送人 " width="133" header-align="center"></vxe-table-column>
                        <vxe-table-column field="recieve_host" title="检验科接收电脑 " width="135" header-align="center"></vxe-table-column>
                        <vxe-table-column field="rcvmsg" title="有效签收 " width="95" header-align="center"></vxe-table-column>
                    </vxe-table>
                    <div class="table-bottom">
                          <div style="font-size: 17px; padding-top: 3px; background-color: #fff; text-align: center; font-weight: bold">
                                <span style="color: red; margin-left: 10px; color: blue">已收: {{ rcvcnt }}</span
                                ><span style="color: red; margin-left: 35px">无效: {{ uninvalidcnt }}</span>
                            </div>
                    </div>
                </div>
            </rm-layout-right>
        </div>
    </div>
</template>

<script type="text/javascript">
export default {
    name: "LIS214",
    data() {
        return {
            chkPatInfo: localStorage.getItem("lis214patinfo"),
            chkDelItem: localStorage.getItem("lis214delitem"),
            chkMixInfo:"0",
            chkItemInfo: "1",
            txtbarcode: "",
            loading: false,
            right_loading: false,
            detail: [],
            master: [],
            buttonwidth: "",
            uninvalidcnt: 0,
            rcvcnt: 0,

            showchkDelItem: "0",
            reqlogColumn: [
                { field: "log_date", title: "操作日期", width: 120 },
                { field: "trans_type", title: "操作类型", width: 70 },
                { field: "log_content", title: "操作内容", width: 200 },
                { field: "username", title: "操作者", width: 60 },
                { field: "computer_name", title: "操作时机器名", width: 96 },
                { field: "mac_address", title: "操作时机器MAC", width: 100 },
                { field: "syncflag", title: "同步HIS标志", width: 100 },
                { field: "synctime", title: "同步时间", width: 120 },
                { field: "syncerrtext", title: "同步失败信息", width: 200 },
                { field: "ref_user", title: "相关人员", width: 80 },
                { field: "labgroupid", title: "相关工作组", width: 80 },
                { field: "barcode", title: "条码号", width: 100 },
            ],
            reqLogData: [],
            tablekey: 0,
        };
    },
    created() {
        this.getButtonWidth();
        this.getOptions(); //初始化主列表
        //this.getinitdata(); //初始化下拉框的数据
    },
    mounted() {
        this.$refs.refbarcode.focus();
    },
    updated() {},
    methods: {
        BarCodeSelect() {
            this.$refs.refbarcode.select();
        },
        getButtonWidth() {
            if (this.$refs.buttondiv) {
                this.buttonwidth = this.$refs.buttondiv.offsetWidth - 200 + "px";
            }
        },
        btnClear() {
            this.master = [];
            this.detail = [];
            this.reqLogData = [];
            this.txtbarcode = "";
            this.$refs.refbarcode.focus();
            this.chkItemInfo = "1";
            this.rcvcnt = 0;
            this.uninvalidcnt = 0;
        },
        HightlightPos(myValue) {
            if (myValue == "") {
                return false;
            }
            var myField = document.getElementById("barcodediv");
            if (myField.selectionStart || myField.selectionStart === 0) {
                var startPos = myField.selectionStart;
                var endPos = myField.selectionEnd;
                this.$nextTick(() => {
                    myField.selectionStart = 0;
                    myField.selectionEnd = startPos + myValue.length;
                }); // 这句是重点, 圈起来
                myField.focus();
                myField.setSelectionRange(myField, myField.selectionStart, myField.selectionEnd);
            }
        },
        async scanbarcode(txtbarcode) {
            var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
            if (reg.test(this.txtbarcode)) {
                //避免弹窗后按钮回车再次走入这个事件
                return false;
            }
            let data = this.$refs.left_Table.getTableData().fullData;
            if (data.length > 0) {
                let findobj = data.find((item) => item.barcode == this.txtbarcode);
                if (!!findobj) {
                    if (this.txtbarcode.indexOf(" 重复扫描条码") > -1) {
                        this.getdetails(findobj[0].barcode);
                        this.$refs.left_Table.setCurrentRow(findobj[0]);
                        this.HightlightPos(this.txtbarcode);
                        return false;
                    } else {
                        this.txtbarcode = txtbarcode + " 重复扫描条码";
                        this.getdetails(findobj[0].barcode);
                        this.$refs.left_Table.setCurrentRow(findobj[0]);
                        this.HightlightPos(this.txtbarcode);
                        return false;
                    }
                }
            }

            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS214",
                    method: "post",
                    data: {
                        action: "scanbarcode",
                        barcode: this.txtbarcode,
                        chkPatInfo: this.chkPatInfo,
                        chkItemInfo: this.chkItemInfo,
                        deleteItem: this.chkDelItem,
                        chkMixInfo:this.chkMixInfo,
                    },
                });
                if (res.flag > 0) {
                    //flag代表返回的数据数目
                    res.master.rcvmsg = "1";
                    res.master.tubecolor = res.retcolor == 0 ? null : res.retcolor;
                    this.master.splice(0, 0, res.master);
                    this.detail = res.details;
                    this.$refs.left_Table.setCurrentRow(res.master);
                    this.getReqLog(txtbarcode);
                    this.rcvcnt++;
                    this.txtbarcode = res.msgList + " 成功！";
                } else if (res.flag == "-99") {
                    this.txtbarcode = res.errmsg;
                } else {
                    this.txtbarcode = res.msgList;
                }
                this.HightlightPos(this.txtbarcode);
            } catch (e) {}
        },
        currentChangeEvent({ row }) {
            this.getdetails(row.barcode);
            this.getReqLog(row.barcode);
        },
        async getdetails(barcode) {
            const res = await this.$tool.request({
                url: "LIS/LIS2/LIS214",
                method: "post",
                data: {
                    action: "getdetails",
                    barcode: barcode,
                },
            });
            this.detail = res.details;
        },
        getReqLog(barcode) {
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS214",
                    method: "post",
                    data: {
                        action: "getreqlog",
                        barcode: barcode,
                    },
                })
                .then((res) => {
                    this.reqLogData = res.reqlog;
                })
                .catch((e) => {
                    this.$alert(e, "信息");
                });
        },
        getOptions() {
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS214",
                    method: "post",
                    data: {
                        action: "getOptions",
                    },
                })
                .then((res) => {
                    this.showchkDelItem = res.delitemflag;
                })
                .catch((e) => {
                    this.$alert(e, "出错");
                });
        },
        formatfun({ row, column, cellValue }) {
            if (column.property == "trans_type") {
                try {
                    let data = this.$opt.ReqLogTransType.find((m) => m.value == cellValue);
                    if (!!data) {
                        return data.label;
                    } else {
                        return cellValue;
                    }
                } catch (e) {
                    return cellValue;
                }
            } else {
                return cellValue;
            }
        },
        repalceComputerName(row) {
            this.$pub.getComputerName(row.mac_address)
                .then((name)=> {
                    row.computer_name = name;
                })
                .catch(()=> {
                    this.$message.error("机器名称查询失败！");
                    //保持原样
                });
        },
        rightclick() {
            this.tablekey++;
        },
        patinfochange() {
            localStorage.setItem("lis214patinfo", this.chkPatInfo);
        },
        delitemchange() {
            localStorage.setItem("lis214delitem", this.chkDelItem);
        },

        
    },
};
</Script>

<style scoped>
.pagetop {
    width: 100%;
    height: 75px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
}

.pagecenter {
    position: absolute;
    top: 80px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.middle-center {
    position: absolute;
    height: 100%;
    left: 0px;
    right: 505px;
    overflow: auto;
}

.middle-right {
    position: absolute;
    height: 100%;
    width: 500px;
    right: 0px;
}

.table1style tr td {
    padding: 0px 5px 2px 5px;
}

.table-bottom {
    position: absolute;
    left: 0px;
    bottom: 0%;
    z-index: 1;
    overflow: hidden;
    width: 100%;
}

</style>